package org.example.chat.validate;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cheval
 */
public class ValidateUtils {

    public static Map<String,String> getValidationErrMsg(BindingResult bindingResult) {
        Map<String,String> err = new HashMap<>();
        List<FieldError> errors = bindingResult.getFieldErrors();
        for (FieldError error : errors) {
            String field = error.getField();
            String message = error.getDefaultMessage();
            err.put(field,message);
        }
        return err;
    }
}
